package com.qishi.exampleTwo;

import org.springframework.aop.framework.ProxyFactory;

public class TestBeforeAdvice {


    public static void main(String[] args) {
        Waiter target = new NaiveWaiter();
        GreetingBeforeAdvice advice = new GreetingBeforeAdvice();

        //spring 提供的代理工厂
        ProxyFactory pf = new ProxyFactory();
        //使用cglib技术进行代理
        pf.setTarget(target);

        pf.addAdvice(0,advice);


        Waiter proxy = (Waiter)pf.getProxy();
        proxy.greetTo("John");
        proxy.serviceTo("John");


        //使用jdk的动态代理技术
        pf.setInterfaces(target.getClass().getInterfaces());
        //对代理进行优化，使得对接口的代理也是运用cglib技术
//        pf.setOptimize(true);
        pf.addAdvice(1,advice);

        Waiter proxy2 = (Waiter)pf.getProxy();
        proxy2.greetTo("John");
        proxy2.serviceTo("John");

    }
}
